﻿using System;
using UnityEngine;
using WoogiWorld.Event;


namespace WoogiWorld.Event
{
    public class EventTester : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            EventDispatcher.Instance.AddEventListener(EventType.anykey_input, this, OnAnyKey);
            EventDispatcher.Instance.AddEventListener(EventType.Notify, this, OnNotify);
        }



        private void OnDestroy()
        {
            EventDispatcher.Instance.RemoveAllEventListener(this);
        }

        private void OnNotify(EventMessage info)
        {
            if (info.CheckData())
            {
                string msg = (string)info.Data;
                Debug.Log(msg);
            }
        }

        private void OnAnyKey(EventMessage info)
        {
            Debug.Log("你操作键盘");
            if (Input.GetKeyDown(KeyCode.B))
            {
                Debug.Log("你正在按B键");
                EventDispatcher.Instance.RemoveEventListener(EventType.anykey_input, this);
            }
        }
    }
}

